package tws

import (
	"log"

	"github.com/gin-gonic/gin"
)

type LoadTemplate struct {
	docBase      string
	resourceList []string
	engine       *gin.Engine
}

func NewLoadTemplate(docBase string, engine *gin.Engine) *LoadTemplate {
	if docBase == "" {
		docBase = "templates/"
	}
	if engine == nil {
		log.Fatal("engine is nil")
		return nil
	}
	return &LoadTemplate{
		docBase: docBase,
		engine:  engine,
	}
}

func (_this *LoadTemplate) AddResource(resource string) {
	if resource == "" {
		log.Fatal("resource is invalid")
		return
	}
	_this.resourceList = append(_this.resourceList, _this.docBase+resource)
}

func (_this *LoadTemplate) Load() {
	if len(_this.resourceList) == 0 {
		log.Fatal("resourceList length is zero")
		return
	}
	_this.engine.LoadHTMLFiles(_this.resourceList...)
}
